<#assign  title="评论、咨询" />
<#include 'common/header.html'/>
<#assign memberIsCommentTag= newTag("memberIsCommentTag")>
<#assign isComment = memberIsCommentTag("{'goods_id':${goods_id!''}}") >	

<#-- 创建商品评论数量标签 -->
<#assign commontGradenNumTag= newTag("commontGradenNumTag")>
<#assign gradenNum= commontGradenNumTag("'goods_id':${goods_id!''}")!'' >
<link rel="stylesheet" type="text/css" href="themes/wap/css/goods.css" />
<!-- 商品详细头部 -->
<div class="header-tools goods-comment">
	<div class="go-back">
		<a href="javascript: void(0);" onclick="window.history.go(-1)"></a>
	</div>
	<div class="common-title">
		评论、咨询
	</div>
	<div class="go-search">
	</div>
</div>

<!-- 标签切换 -->
<div class="switch-tab-box">
	<ul>
		<li rel="comment" class="selected"><span>商品评论</span></li>
		<li rel="ask"><span>商品咨询</span></li>
	</ul>
</div>
<!-- 评论分类 -->
<div class="comment-tab-list">
	<ul>
		<li class="height_grade selected" rel="4"><span>全部(${gradenNum.allCommentNum!0})</span></li>
		<li class="height_grade" rel="3"><span>好评(${gradenNum.gradeHigh!0})</span></li>
		<li class="middel_grade" rel="2"><span>中评(${gradenNum.gradeTwo!0})</span></li>
		<li class="low_geade" rel="1"><span>差评(${gradenNum.gradeLow!0})</span></li>
	</ul>
</div>
<div class="goods-comment-box">
	<!-- 商品评论 -->
	<div class="goods-comment-list">
		
	</div>
	
	<!-- 提交评论 -->
	<!--<div class="goods-comment-from">
		<form action="#" method="post" id="discussForm"  >
			<input type="hidden" name="goods_id" value="${goods_id!''}" />
			<input type="hidden" name="commenttype" value="1" />
			<h2 class="goods_comment_grade">
					<b>评分：</b>
					<label>
						<input type="radio" checked="checked" value="3" name="grade" style="width:auto;">
						<i class="score_fine"></i>
						<span>（好评）</span>
					</label>
					<label>
						<input type="radio" value="2" name="grade" style="width:auto;">
						<i class="score_middle"></i>
						<span>（中评）</span>
					</label>
					<label>
						<input type="radio" value="1" name="grade" style="width:auto;">
						<i class="score_no"></i>
						<span>（差评）</span>
					</label>
				</h2>
				<div class="comment_box">
					<textarea name="content" id="discuss_content" placeholder="请在此处输入您的评论"></textarea>
					<div class="btn">
						<a href="javascript:void(0)" class="blue_btn green-btn save-comment" id="discussBtn">发表评论</a>
					</div>
				</div>
		</form>
	</div>-->
</div>
<div class="goods-ask-box" style="display:none">
	<!-- 咨询 -->
	<div class="goods-ask-list">
	</div>
	<!-- 提交咨询 -->
	<div class="goods-ask-from">
		<form method="post" id="askForm"   >
			<input type="hidden" name="goods_id" value="${goods_id!''}" />
			<input type="hidden" name="commenttype" value="2" />
			<div class="ask_issue">
					<textarea  name="content" id="ask_content" placeholder="请在此处输入您的问题"></textarea>
			 		<div class="btn">
						<a href="javascript:;" class="yellow-btn save-ask" id="askBtn" >提交咨询</a>
					</div>
			</div>	
		</form>
	</div>
</div>

<!-- 回到顶部 -->
<div class="go-top" style="display:none;">
	<a href="javascript:;viod(0)"></a>
</div>

<script>
	$(function(){
		loadDiscuss_wrapper_list(1);
	//	loadAsk_wrapper_list(1);
		
		//评论咨询切换
		$(".switch-tab-box ul li").click(function(){
			$(".switch-tab-box ul li").removeClass("selected");
			$(this).addClass("selected");
			var isAsk = $(this).attr("rel");
			if(isAsk=="ask"){
				$(".goods-comment-box").hide();
				$(".comment-tab-list").hide();
				$(".goods-ask-box").show();
				$(".goods-ask-list").empty();
				loadAsk_wrapper_list(1);
			}else{
				$(".comment-tab-list").show();
				$(".goods-comment-box").show();
				$(".goods-ask-box").hide();
				
			//	$(".goods-comment-box").empty();
				loadDiscuss_wrapper_list(1);
			}
		})
		
		//评论切换
		$(".comment-tab-list ul li").click(function(){
			var gradeNum = $(this).attr("rel");
			if(gradeNum == 4){
				loadDiscuss_wrapper_list(1);
			}else{
				loadDiscuss_grade_list(1,gradeNum);
			}
			
			$(".comment-tab-list ul li").removeClass("selected");
			$(this).addClass("selected");
		})
		
		//商品评论
		function loadDiscuss_wrapper_list(page){
			$(".goods-comment-list").load("discuss_list.html?goods_id="+${goods_id}+"&page="+page,function(){
				$(".goods-comment-list .page li a").click(function(){
					var pageno= $(this).attr("page");
					loadDiscuss_wrapper_list(pageno);
				});
			});	
		}
		
		//商品评论分级
		function loadDiscuss_grade_list(page,grade){
			$(".goods-comment-list").load("grade_list.html?goods_id="+${goods_id}+"&page="+page+"&grade="+grade,function(){
				$(".goods-comment-list .page li a").click(function(){
					var pageno= $(this).attr("page");
					loadDiscuss_wrapper_list(pageno);
				});
			});	
		}
		
		function loadAsk_wrapper_list(page){
			$(".goods-ask-list").load("ask_list.html?goods_id="+${goods_id}+"&page="+page,function(){
				$(".goods-ask-list .page li a").click(function(){
					var pageno= $(this).attr("page");
					loadAsk_wrapper_list(pageno);
				});
			});	
		}
		
		//提交评论，暂时不支持图片上传
		$(".save-comment").click(function(){
			
			<#if !isComment.isLogin >
				alert("请您先登录，然后再进行评论！");
				return;
			<#else>
				<#if !isComment.isBuy>
					alert("您只有购买该商品后才能进行评论！");
					return;
				<#else>
					<#if isComment.isCommented>
						alert("对不起，您已经评论过此商品！");
						return;
					<#else>
						var cval = $('#discuss_content').val();
						if(cval == '' ||cval=='请在此处输入您的评论' ){
							alert("请输入您的评论内容！");
							return;
						}
						else if(cval.length>1000){
							alert("请您输入1000字以内的评论");
							return;
						}
						$(".save-comment").attr("disabled",false); 
						var options = { 
								url :ctx + "/api/shop/commentApi/add.do",
								type : "POST",
								dataType : "json",
								success : function(result) {
					 				if(result.result==1){
										 alert("提交成功，请等待管理员审核!");
										 window.location.reload();
							 		}else{
							 			alert(result.message);
							 			$(".save-comment").attr("disabled",false); 
								 	}
								},
								error : function(e) {
									alert("出现错误 ，请重试");
									$(".save-comment").attr("disabled",false); 
								}
						};
						$("#discussForm").ajaxSubmit(options);
					</#if>
				</#if>
			</#if>
		})
		
		
		//提交咨询
		$(".save-ask").click(function(){
			$(".save-ask").attr("disabled",true); 
			var cval = $('#ask_content').val();
			if(cval == '' ||cval=='请在此处输入您的问题' ){
				alert("请输入您的咨询内容！");
				return;
			}
			else if(cval.length>1000){
				alert("请您输入1000字以内的文字");
				return;
			}
			var options = { 
					url :ctx + "/api/shop/commentApi/add.do",
					type : "POST",
					dataType : "json",
					success : function(result) {
		 				if(result.result==1){
							 alert("提交成功，请等待管理员审核!");
							 $("#askForm").get(0).reset();
							 window.location.reload();
				 		}else{
				 			alert(result.message);
				 			$(".save-ask").attr("disabled",false); 
					 	}
					},
					error : function(e) {
						alert("出现错误 ，请重试");
						$(".save-ask").attr("disabled",false); 
					}
			};
			$("#askForm").ajaxSubmit(options);
			
		})
	})
</script>


<#include 'common/footer.html'/>
